/*
 * @(#)UserAddServiceImpl.java 创建于 2014年3月14日 
 * 
 * Copyright (c) 2013-2014 by Drow.  
 *
 */
package com.hangxin.basic.service.impl;

import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hangxin.basic.dao.CompanyDao;
import com.hangxin.basic.dao.CustomerDao;
import com.hangxin.basic.dao.UserDao;
import com.hangxin.basic.model.Customer;
import com.hangxin.basic.model.LoginInfo;
import com.hangxin.basic.service.CustomerService;
import com.hangxin.basic.service.UserService;
import com.hangxin.commons.service.impl.BasicServiceImpl;
import com.hangxin.commons.util.MD5Util;
import com.hangxin.commons.util.PageModel;

/**
 * 
 * 类名称：UserAddServiceImpl.java
 * <P/>
 * 类描述： 添加登录用户service接口实现方法
 * <P/>
 * 创建时间：2014年3月14日
 * <P/>
 * 创建人： 段志杨
 * <P/>
 * 联系方式：315874529@qq.com
 * <P/>
 * 修改人：无
 * <P/>
 * 修改时间：无
 * <P/>
 * 修改备注：无
 * <P/>
 * 版本：v1.0
 * 
 */
@Service
public class CustomerServiceImpl extends BasicServiceImpl implements CustomerService
{
	@Resource
	private CustomerDao customerDao;

	@Override
	public int customerAdd(Customer customer)
	{
		Object[] params={customer.getCcode(),customer.getCname(),customer.getCnum(),customer.getCadtel(),customer.getCaccount(),customer.getSimno()};
		return customerDao.customerAdd(params);
	}

	@Override
	public PageModel customerManage(PageModel pageModel,String ccode,String cname,String taxno,String cadtel,String caccount)
	{
		Object[] paramscount= new Object[]{"%"+cname+"%","%"+taxno+"%","%"+(cadtel==null?"":cadtel)+"%","%"+(caccount==null?"":caccount)+"%"};
		Object[] params= new Object[]{"%"+cname+"%","%"+taxno+"%","%"+(cadtel==null?"":cadtel)+"%","%"+(caccount==null?"":caccount)+"%",(pageModel.getPageNo() - 1) * pageModel.getPageSize(),pageModel.getPageSize()};
		return customerDao.customerManage(pageModel, paramscount, params);
	}
	
	

	@Override
	public Integer checkName(String cname,String content,Long id){
		Object[] params=null;
		if(id==null){
			params	= new Object[]{cname,content};
		}else{
			params	= new Object[]{cname,content,id};
		}
		
		return customerDao.checkName(params);
	}


	public Map<String,Object> customerFind(Long id){
		Object[] params= new Object[]{id};
		return customerDao.customerFind(params);
	}
	

	@Override
	public void customerEdit(Customer customer)
	{
		Object[] params= new Object[]{customer.getCcode(),customer.getCname(),customer.getCnum(),customer.getCadtel(),customer.getCaccount(),customer.getSimno(),customer.getId()};
		customerDao.customerEdit(params);
	}
	@Override
	public Integer customerDel(Long id){
		Object[] params= new Object[]{id};
		return customerDao.customerDel(params);
	}
	
	@Override
	public List<Map<String , Object>> findCustomers(String name){
		Object[] params= new Object[]{"%"+name+"%"};
		return customerDao.findCustomers(params);
	}
	
	@Override
	public List<Map<String , Object>> findCustomer(String name){
		Object[] params= new Object[]{name};
		return customerDao.findCustomer(params);
	}
	
	@Override
	@Transactional
	public Integer custImportSave(String strname) {
		Integer n = 0;
		StringBuffer sdf = new StringBuffer("");
		strname = strname.replaceAll("\"", "");
		String[] strarys = strname.split("_");
		String[] array = null;
		for(String strary:strarys){
		   String[] strs = strary.split("~~");
		   array = new String[9];
		   for(int i=0;i<strs.length;i++){
			   array[i] = strs[i];
		   }
		   array[0] = array[0]== null?"":array[0];
		   array[1] = array[1]== null?"":array[1];
		   array[2] = array[2]== null?"":array[2];
		   array[3] = array[3]== null?"":array[3];
		   array[4] = array[4]== null?"":array[4];
		   array[5] = array[5]== null?"":array[5];
		   customerDao.custImportSave(array);
		}
		n++;
		return n;
	}
	
}
